<?php
// Set IP BEGIN:
if(!isset($_SESSION['USER_IP']) || $_SESSION['USER_IP'] == NULL){
    session_register('USER_IP');
    $_SESSION['USER_IP'] = get_real_ip();
    update_ip($_SESSION['USER_IP'],0);
}
// Set IP END.
//xử lý id và pages được gửi xuống
//if(isset($_GET['cat'])) $cat=killInjection(substr($_GET['cat'],0,strpos($_GET['cat'],'-')));
if(isset($_GET['id'])) $id= intval(killInjection($_GET['id']));
if(isset($_GET['cat'])) $cat= intval(killInjection($_GET['cat']));
if(isset($_GET['p'])) $p = intval(killInjection($_GET['p']));
//xác định trang được gọi
if(isset($_GET['frame'])){
    $frame=killInjection($_GET['frame']);
    if($_GET['keyword']=='category') {$frame=8;}
    switch ($frame){
        case 1:
            $pages='product_detail';
			$cururl = $curHost.$_GET['cat'].'/'.$_GET['ali'].'/'.$frame.'/'.$id.'.html';
            break;
        case 2:
            $pages='news';
			$cururl = $curHost.$_GET['cat'].'/'.$_GET['ali'].'/'.$frame.'/'.$id.'.html';
            break;
        case 3:
            $pages='news_detail';
			$cururl = $curHost.$_GET['cat'].'/'.$_GET['ali'].'/'.$frame.'/'.$id.'.html';
            break;
        case 4:
            $pages='product_sub';
			$cururl = $curHost.$_GET['cat'].'/'.$_GET['ali'].'/'.$frame.'/'.$id.'.html';
            break;
        case 5:
            $pages='contact_pro';
			$cururl = $curHost.$_GET['cat'].'/'.$_GET['ali'].'/'.$frame.'/'.$id.'.html';
            break;
        case 6:
            $pages='news_sub';
			$cururl = $curHost.$_GET['cat'].'/'.$_GET['ali'].'/'.$frame.'/'.$id.'.html';
            break;
        case 7:
            $pages='product';
			$cururl = $curHost.$_GET['cat'].'/'.$_GET['ali'].'/'.$frame.'/'.$id.'.html';
            break;
        case 8:
            $pages='keyword';
			$cururl = $curHost.$_GET['keyword'].'/'.$id.'.html';
            break;
        default:
            $pages=utf8_to_ascii($_GET['frame']);
			$cururl = $curHost;
            break;
    }
}else{
    $pages=utf8_to_ascii($_REQUEST['frame']);
	$cururl = $curHost;
}
//viết các chỉ số title, description, keyword
if($_GET['id']){
    if($pages=='product_detail'){
        $product = getRecord('xteam_product','id='.$id);
        $description = $product['description']!=''?$product['description']:catchu($product['detail'],160);
        $title=$product['title']!=''?$product['title']:$product['name'];
    }

    if($pages=='product' || $pages=='product_sub'){
        $category = getRecord('xteam_category','id='.$id);
        $description = $category['description']!=''?$category['description']:$mydescription['detail'];
        $title=$category['title']!=''?$category['title']:'';
    }

    if($pages=='news_detail'){
        $news = getRecord('xteam_content','id='.$id);
        $description = $news['description']!=''?$news['description']:catchu($news['detail'],160);
        $title=$news['title']!=''?$news['title']:$news['name'];
    }

    if($pages=='news' || $pages=='news_sub'){
        $category = getRecord('xteam_category','id='.$id);
        $description = $category['description']!=''?$category['description']:$mydescription['detail'];
        $title=$category['title']!=''?$category['title']:'';
    }

}else{
    $description = $mydescription['detail'];
}
//chuẩn hóa utf-8 cho title, description
$description = html_entity_decode(strip_tags($description), ENT_QUOTES, 'UTF-8');
$title = $title!='' ? $title : $mytitle['detail'];
//xác định chuyên mục bài viết
$newscatname = array();
$newscatali = array();
$getnews = getRecord('xteam_category', 'code="news"');
$cat_news =  getArray('xteam_category','status=1 AND parent_id='.$getnews['id'].' AND top_menu=1',NULL,"sort");
if($cat_news){
    foreach($cat_news as $cat_new){
        $list_news_id .= $cat_new['id'].',';
        $newscatname[$cat_new['id']]=$cat_new['name'];
        $newscatali[$cat_new['id']]=$cat_new['seo_key'];
    }
    $filter_news = 'parent_id IN ('.substr($list_news_id,0,-1).')';
    $top_news = getArray('xteam_content','status=1 AND '.$filter_news);
}

//xác định chuyên mục sản phẩm
$parname = array();
$parid = array();
$parseokey= array();
$getpro = getRecord('xteam_category', 'code="product"');
$cat_pro =  getArray('xteam_category','status=1 AND parent_id='.$getpro['id'],NULL,"sort");
if($cat_pro){
    foreach($cat_pro as $parent){
        $list_pro_id .= $parent['id'].',';
		$parname[$parent['id']] = $parent['name'];
		$parid[$parent['id']] = $parent['id'];
		$parseokey[$parent['id']] = utf8_to_ascii($parent['seo_key']);
    }
    $filter_pro = 'parent_id IN ('.substr($list_pro_id,0,-1).')';
    $top_pro = getArray('xteam_product','status=1 AND '.$filter_pro);
}?>